<template>
	<view>
		<view class="d-flex j-sb p-1 border main-text-color font">
		
			<view class="center">
				设备名称
			</view>
			<view class="center">
				设备编号
			</view>
		</view>
		<view   class="flex_new">
			<view class="d-flex main-text-color_2 font flex-1 border-bottom pd_n"
				v-for="(item,index) in getdevice" :key="index" @tap="toditel(item.equipmentNumber)">
				<block>
					
					<view class="center">
						{{item.equipmentName}}
					</view>
					<view  class="center ">
						{{item.equipmentNumber}}
					</view>
				</block>
			</view>
		</view>
		<view class="build_bttom_page d-flex j-sb p-3 a-center" >
			<view class="d-flex a-center">
				<image src="../../static/image/left.png" mode="widthFix" style="width: 20rpx;height: 20rpx;"></image>
				<view class="pl-2 font" @tap="paging(1)">
					上一页
				</view>
			</view>
			<view style="padding-left: 165rpx;padding-right: 150rpx;">
				<view class="main-bg-color d-flex j-center a-center"
					style="width: 120rpx;height: 48rpx;border-radius: 50rpx;color: #fff;">
					第{{pageNum}}页
				</view>
			</view>
			<view class="d-flex a-center" @tap="paging(2)">
				<view class="pr-2 font">
					下一页
				</view>
				<image src="../../static/image/right.png" mode="widthFix" style="width: 20rpx;height: 20rpx;"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				getdevice: [],
				//建筑详情id
				buildingId: '',
				pageNum: 1,
				//设备编号
				equipmentNumber: ''
			};
		},
		onLoad(w) {
			this.buildingId = w.buildingId
			console.log(this.buildingId, '建筑详情id');
		},
		onShow() {
			//获取设备列表
			this.get_device(this.buildingId)
		},
		methods: {
			//获取设备列表
			get_device(e) {
				this.$https.get("system/equipment/wxfindallequment", {
					buildingId: this.buildingId,
					pageNum: this.pageNum,
					pageSize: 10,
				}).then(res => {
					this.getdevice = res.rows
					this.equipmentNumber = res.rows.equipmentNumber
					console.log(this.getdevice, 'this.getdevice');
				})
			},
			//去设备详情
			toditel(e) {
				console.log(e, '设备编号');
				uni.navigateTo({
					url: "./device_detail?equipmentNumber=" + e
				})
			},
			//分页
			paging(e) {
				switch (e) {
					case 1:
						if (this.pageNum == 1) {
							this.pageNum == 1
							uni.showToast({
								title: '已经是第一页了！',
								icon: 'none'
							})
						} else {
							this.pageNum--
							this.$https.get('system/equipment/wxfindallequment', {
								buildingId: this.buildingId,
								pageSize: 10,
								pageNum: this.pageNum
							}).then(res => {
								this.getdevice = res.rows
							})
						}
						break;
					case 2:
						this.$https.get('system/equipment/wxfindallequment', {
							buildingId: this.buildingId,
							pageSize: 10,
							pageNum: this.pageNum + 1
						}).then(res => {
							console.log(res, 'res');
							if (res.rows.length == 0) {
								uni.showToast({
									title: '无更多数据',
									icon: 'none'
								})
							} else {
								this.pageNum++
								this.getdevice = res.rows
							}

						})
						break;
				}
			},
		}

	}
</script>

<style lang="scss" scoped>
.flex_new{
		height: calc(100vh - 210rpx);
	}
	.flex_new>view{
		height: 10%;
		display: flex;
		align-items: center;
	}
.build_bttom_page{
	width: 100%;
	position: fixed;
	box-sizing: border-box;
	bottom: 0rpx;
	box-shadow: 0 0 6rpx 0 rgba(0, 0, 0, 0.1);
}
.center{
	flex: 1;
	text-align: center;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}
</style>
